<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/style.css" media="all">
	<script src="${pageContext.request.contextPath}/layui/layui.all.js"></script>
</head>
<body>
<div class="layadmin-header">
	<div class="layui-breadcrumb" lay-filter="breadcrumb">
		<a><cite>信号灯与停车区域关联设置</cite></a>
	</div>
</div>

<div class="layui-fluid mainBody">
	<div class="layui-row">
		<div>
			<table class="layui-hide" id="test" lay-filter="test"></table>
		</div>
	</div>
</div>
</body>
</html>

<script>

	var $ = layui.$,
			admin = layui.admin,
			table = layui.table;
	var test = table.render({
		elem: '#test',
		url: '${pageContext.request.contextPath}/signLight/getSignLightList',
		method: 'post',
		toolbar: '<div><a class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>新增</a><a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a></div>',
		skin: 'line',
		size: 'lg' ,
		cols: [[
			{type:'checkbox'}
			// ,{field:'areaName', width:150, title: '区域'}
			,{field:'lightname',  title: '信号灯名称'}
			,{field:'ip',  title: 'ip'}
			,{field:'port',  title: '端口'}
			,{field:'lightdirection',  title: '方向'}
			,{field:'status',  title: '状态'}
			,{
				field:'', width:135, align: 'center', title: '操作', templet: function (data) {
					return '<a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="edit">编辑</a><a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="del">删除</a>';
				}
			}
		]],
		page:true,
		response: {
			statusName: 'code' //规定数据状态的字段名称，默认：code
			,statusCode: 200 //规定成功的状态码，默认：0
			,msgName: 'msg' //规定状态信息的字段名称，默认：msg
			,countName: 'total' //规定数据总数的字段名称，默认：count
			,dataName: 'data' //规定数据列表的字段名称，默认：data
		},
		request: {
			pageName: 'curr' //页码的参数名称，默认：page
			,limitName: 'nums' //每页数据量的参数名，默认：limit
		}
	});
	//头工具栏事件
	table.on('toolbar(test)', function(obj) {
		var data = table.checkStatus(obj.config.id).data;
		switch (obj.event) {
			case 'add':
				layer.open({
					type: 2,
					title:false,
					shade: 0.8,
					area: ['800px', '520px'],
					content: '${pageContext.request.contextPath}/iframe/setSignalItem.html?type=add',
					end: function() {
						test.reload();
					}
				});
				break;
			case 'del':
				var ids=[];
				data.forEach(function (e) {
					ids.push(e.id);
				});
				del(ids.join(","));
				break;
		}
	});
	//行工具栏事件
	table.on('tool(test)', function(obj) {
		var data = obj.data;
		switch (obj.event) {
			case 'edit':
				layer.open({
					type: 2,
					title:false,
					shade: 0.8,
					area: ['800px', '520px'],
					content: '${pageContext.request.contextPath}/iframe/setSignalItem.html?type=edit&id='+data.id,
					end: function() {
						test.reload();
					}
				});
				break;
			case 'del':
				del(data.id);
				break;
		}
	});

	function del(ids) {
		layer.confirm("确定要删除",function () {
			$.ajax({
				type:"post",
				url:"${pageContext.request.contextPath}/signLight/delete",
				data:{id:ids},
				success:function (res) {
					if (res=='200'){
						layer.msg("删除成功",{'icon':1,'offset': '100px'});
					}
					if (res=='201'){
						layer.msg("删除失败",{'icon':5,'offset': '100px'});
					}
					test.reload();
				}
			})
		})
	}
</script>